local sk__souying = fk.CreateSkill {

  name = "sk__souying",

  tags = {  },

}



sk__souying:addEffect(fk.CardRespondFinished, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__souying.name) then
      if data.card.trueName == "slash" then
        return table.find(player.room.alive_players, function(p)
          return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
        end)
      elseif data.card.trueName == "jink" then
        return table.find(player.room.alive_players, function(p)
          return not table.contains(player:getTableMark("sk__souying2-turn"), p.id) and p:isWounded()
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets, n = {}, 1
    if data.card.trueName == "slash" then
      targets = table.map(table.filter(room.alive_players, function(p)
        return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
      end), Util.IdMapper)
    elseif data.card.trueName == "jink" then
      n = 2
      targets = table.map(table.filter(room.alive_players, function(p)
        return not table.contains(player:getTableMark("sk__souying1-turn"), p.id)
      end), Util.IdMapper)
    end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#sk__souying"..n.."-invoke", sk__souying.name, true)
    if #to > 0 then
      event:setCostData(self, {to[1], n})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(sk__souying.name)
    local to = room:getPlayerById(event:getCostData(self)[1])
    local n = event:getCostData(self)[2]
    local mark = player:getTableMark("sk__souying"..n.."-turn")
    table.insertIfNeed(mark, to.id)
    room:setPlayerMark(player, "sk__souying"..n.."-turn", mark)
    if n == 1 then
      room:notifySkillInvoked(player, sk__souying.name, "offensive")
      room:damage({
        from = player,
        to = to,
        damage = 1,
        skillName = sk__souying.name,
      })
    else
      room:notifySkillInvoked(player, sk__souying.name, "support")
      if to:isWounded() then
        room:recover{
          who = to,
          num = 1,
          recoverBy = player,
          skillName = sk__souying.name
        }
      end
    end
  end,
})

return sk__souying